<?php
class addAction extends rareAction{
	public function execute(){
		$type = $this->getGetParam('type',0);
		$this->assign('type',$type);
		if(Tool::_getCache('isAdmin')){
			if($type == service_type::PRODUCT){
				Tool::_setCache('current','product');
			}elseif($type == service_type::NEWS){
				Tool::_setCache('current','news');
			}
		}else{
			Tool::_setCache('currentID',service_menu::getCurrent('1',$type));
		}
	}
	public function executePost(){
		$type = $this->getPostParam('type',0);
		if($type==0) jsonReturn(0,'no');
		$cate = $this->getPostParam('cate',array());
		if(empty($cate)) jsonReturn(0,'null');
		$cate['typeID'] = $type;
		$cateDao = new DaoCategory();
		$cate['title'] = trim($cate['title']);
		$cate['description'] = trim($cate['description']);
		$re = $cateDao->insert($cate);
		$parent = $cateDao->getOne('id='.$cate['parentID']);
		if(empty($parent)){
			$path = "0,$re";
		}else{
			$path = $parent['path'].",$re";
		}
		$cateDao->update("id='$re'",array('path'=>$path));
		jsonReturn(1,'ok');
	}
}
?>
